package com.fanrenqiji.modules.sys.dao;

import com.fanrenqiji.common.persistence.BaseDao;
import com.fanrenqiji.common.persistence.BaseDaoImpl;
import com.fanrenqiji.modules.sys.entity.Role;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

/**
 * @author lijian E-mail:ljz0721cx@163.com
 * @version 创建时间：2015年1月21日 下午5:11:04
 * @description
 * 用户角色持久对象
 */
public interface RoleDao extends RoleDaoCustom, CrudRepository<Role, Long> {

	@Query("from Role where name = ?1 and delFlag = '" + Role.DEL_FLAG_NORMAL + "'")
	Role findByName(String name);
	@Query("from Role where enName = ?1 and delFlag = '" + Role.DEL_FLAG_NORMAL + "'")
	Role findByEnName(String enName);
	
	
	@Query(nativeQuery = true, value = "SELECT count(*) counts FROM sys_user_role sur, sys_user su, ( SELECT * FROM sys_role WHERE en_name = ?1 ) sr, sys_office so WHERE sur.user_id = su.id AND sur.role_id = sr.id AND su.office_id = so.id AND su.office_id = ?2")
	Long countByOfficeBelowRole(String enName, Long officeId);
	

}

interface RoleDaoCustom extends BaseDao<Role>{
}

@Repository
class RoleDaoImpl extends BaseDaoImpl<Role> implements RoleDaoCustom{

}